<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\client;

use app\model\AccountApplyDetailModel;
use app\model\AccountPortModel;
use app\model\AccountProductSalesmanModel;
use app\model\ClientProductModel;
use app\service\BaseService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;

final class ProductService extends BaseService
{
    /**
     * 获取产品关联人员.
     * @param int $productId 产品id
     * @param int $mediaId 媒体id
     * @param int $accountType 账户类型
     * @return null|AccountProductSalesmanModel|array|mixed|Model
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getProductSalesman(int $productId = 0, int $mediaId = 0, int $accountType = 0)
    {
        $where = [
            ['product_id', '=', $productId],
            ['media_id', '=', $mediaId],
            ['account_type', '=', $accountType],
        ];
        return (new AccountProductSalesmanModel())->where($where)->find();
    }

    /**
     * 获取端口信息.
     * @param string $advertiserId 账户id
     * @return null|AccountPortModel|array|mixed|Model|void
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getPort(string $advertiserId = '')
    {
        return (new AccountPortModel())->where('advertiser_id', $advertiserId)->find();
    }

    /**
     * 获取产品名.
     * @param int $id 产品id
     * @return null|AccountPortModel|array|mixed|Model|void
     */
    public static function getProductName(int $id = 0)
    {
        return (new ClientProductModel())->where('id', $id)->value('product_name');
    }

}
